window.onload = function () {
    var miaov = document.getElementById('miaov');
    // 获取元素
    var oFill = document.getElementById('fill_in');
    // 获取输入框
    var oInputYear  = oFill.getElementsByTagName("input")[0];
    var oInputMonth = oFill.getElementsByTagName("input")[1];
    var oInputDay   = oFill.getElementsByTagName("input")[2];
    // 获取按钮
    var oBtn = document.getElementById('go2');

    // 获取day
    var textDay = document.getElementById('day');
    // 获取hour
    var textHour = document.getElementById('hour');
    // 获取min
    var textMin = document.getElementById('min');
    // 获取sec
    var textSec = document.getElementById('sec');

    // 获取date 
    var date1 = document.getElementById('target').getElementsByTagName("strong")[0];
    

    oBtn.onclick = function () {
        date1.innerHTML = oInputYear.value + "年" + oInputMonth.value + "月" + oInputDay.value + "日";
        setInterval(box,1000);
        // 调用box函数消除定时器延迟
        box();
    }

    function box() {
        // 创建日期对象
        var oDateEnd = new Date();
        // 结束的日期
        var oDateNow = new Date();
        // 获取年
        oDateEnd.setFullYear(parseInt(oInputYear.value));
        // 获取月
        oDateEnd.setMonth(parseInt(oInputMonth.value) - 1);
        // 获取年
        oDateEnd.setDate(parseInt(oInputDay.value));
        // 设置为0点0分0秒
        oDateEnd.setHours(0);
        oDateEnd.setMinutes(0);
        oDateEnd.setSeconds(0);
        // 获取时间戳的同时再获取到秒数
        var iRemain = (oDateEnd.getTime() - oDateNow.getTime()) / 1000;
        // 防止输入小于当天的日期
        if (iRemain < 0 ) {
            return;
        }
        // 获取剩余的天
        var iDay = parseInt(iRemain / 86400);
        iRemain %= 86400;
        // 获取剩余的小时
        var iHour = parseInt(iRemain / 3600);
        iRemain %= 3600;
        // 获取剩余的分钟
        var iMin = parseInt(iRemain / 60);
        iRemain %= 60;
        // 获取剩余的秒
        var iSec = iRemain;

        textDay.innerHTML = iDay;
        textHour.innerHTML = iHour;
        textMin.innerHTML = iMin;
        textSec.innerHTML = iSec;
    }
}